package main

import (
	"fmt"
	"strings"
	"unicode"
)

func check_length(passwd string)bool{
	return len(passwd) > 8
}

func check_cha(passwd string) bool {
	var hasUpper, hasLower, hasNumber,hasSpecial bool
	for _, i := range passwd{
		switch{
		case unicode.IsUpper(i):
			hasUpper = true
		case unicode.IsLower(i):
			hasLower = true
		case unicode.IsNumber(i):
			hasNumber = true
		case unicode.IsPunct(i) || unicode.IsSymbol(i):
			hasSpecial = true
		}
	}
	count := 0
	if hasUpper{
		count ++
	}
	if hasLower{
		count ++
	}
	if hasNumber{
		count ++
	}
	if hasSpecial{
		count ++
	}
	return count >= 3
}

func check_re(passwd string) bool{
	for i := 0; i < len(passwd) - 2;i++{
		if strings.Contains(passwd[i+3:], passwd[i:i+3]){
			return false
		}
	}
	return true
}

func check(passwd string) (int, []string) {
	score := 2
	problems := []string{}

	if check_length(passwd){
		score ++
	}else{
		problems = append(problems,"长度小于8")
	}

	if check_cha(passwd){
		score ++
	}else{
		problems = append(problems,"密码没有由三种以上字符组成")
	}

	if check_re(passwd){
		score ++
	}else{
		problems = append(problems,"有长度超过或等于3的字符串重复")
	}
	return score, problems
}

func main(){
	var passwd string
	fmt.Println("请输入你的密码:")
	fmt.Scan(&passwd)
	score, problems := check(passwd)
	fmt.Println("密码评分等级：",score)
	fmt.Println("需要改进的地方",problems)
}